/**
 * 
 */
package com.lb.store.memcache;

import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.XMemcachedClient;

/**
 * @author LionBule
 * 2012-9-22 下午9:08:41
 */
public class TestClient {
    public static void main(String[] args) throws Exception {
        MemcachedClient client = new XMemcachedClient("10.250.20.9", 12110);
        try {
            String testVal = "LionBule";
            String key = "name";
            boolean success = false;

            //从memcached获取key对应的value
            String rs = (String) client.get(key);
            System.out.println("client.get = " + rs);

            if (rs != null && testVal.equals(rs)) {
                success = client.delete("key");
                System.out.println("client.delete=" + success);
            }

            //同步存储value到memcached，缓存超时为1小时，3600秒。
            client.set(key, 3600, testVal);

            //从memcached获取key对应的value,操作超时2秒
            rs = client.get(key, 2000);
            System.out.println("client.get(exp) = " + rs);

            //        //更新缓存的超时时间为10秒。
            //        boolean success = client.touch(key, 10);
            //        System.out.println("client.touch=" + success);

            //删除value
            success = client.delete("key", 2000L);
            System.out.println("client.delete=" + success);

            rs = (String) client.get(key);
            System.out.println("client.get = " + rs);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            client.shutdown();
        }
    }
}
